package simple.framework.util;

import java.io.*;
import java.util.regex.*;
import javax.xml.xpath.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;

public class sp {

    public conf conf;

    public String cparameter(String argString) {
        String tmpstr = "";
        String tString = argString;
        tString = tString.trim();
        if (tString.substring(0, 1).equals("\"")) {
            tmpstr = cls.getLRStr(cls.getLRStr(tString, "\"", "rightr"), "\"", "leftr");
        } else {
            tString = tString.replace("'", "\"");
            tmpstr = cvalue(tString);
        }
        return tmpstr;
    }

    public String cvalue(String argString) {
        String tString = argString;
        String tFunction, tParameter;
        if (tString != "") {
            tFunction = cls.getLRStr(tString, "(", "left");
            tParameter = cls.getLRStr(cls.getLRStr(tString, "(", "rightr"), ")", "leftr");
            String[] tParameterAry = fixParameterAry(tParameter.split(Pattern.quote(",")));
            Integer tParameterAryLength = tParameterAry.length;
            if (tFunction.equals("$admin.theme")) {
                tString = conf.common.getAdminTheme();
            } else if (tFunction.equals("$adminFolder")) {
                tString = conf.adminFolder;
            } else if (tFunction.equals("$charset")) {
                tString = conf.charset;
            } else if (tFunction.equals("$images")) {
                tString = conf.imagesRoute;
            } else if (tFunction.equals("$global.images")) {
                tString = conf.getActualRoute(conf.imagesRoute);
            } else if (tFunction.equals("$ngenre")) {
                tString = conf.getNGenre();
            } else if (tFunction.equals("$nlng")) {
                tString = conf.getNLng();
            } else if (tFunction.equals("$ntitle")) {
                tString = conf.ntitle;
            } else if (tFunction.equals("$navSpStr")) {
                tString = conf.navSpStr;
            } else if (tFunction.equals("$now")) {
                tString = cls.getDate();
            } else if (tFunction.equals("$nurs")) {
                tString = conf.getNURS();
            } else if (tFunction.equals("$nuri")) {
                tString = conf.getNURI();
            } else if (tFunction.equals("$nurl")) {
                tString = conf.getNURL();
            } else if (tFunction.equals("$nurlpre")) {
                tString = conf.getNURLPre();
            } else if (tFunction.equals("$nuserip")) {
                tString = conf.getRemortIP();
            } else if (tFunction.equals("$sysName")) {
                tString = conf.sysName;
            } else if (tFunction.equals("base64encode")) {
                tString = encode.base64encode(cparameter(tParameter).getBytes());
            } else if (tFunction.equals("concat")) {
                if (tParameterAryLength == 2) {
                    tString = cls.concat(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]));
                }
            } else if (tFunction.equals("curl")) {
                if (tParameterAryLength == 2) {
                    tString = conf.common.curl(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]));
                }
            } else if (tFunction.equals("cdatadecode")) {
                tString = encode.cdatadecode(cparameter(tParameter));
            } else if (tFunction.equals("crValcodeTpl")) {
                tString = conf.common.crValcodeTpl(cparameter(tParameter));
            } else if (tFunction.equals("dateAdd")) {
                if (tParameterAryLength == 3) {
                    tString = cls.dateAdd(cparameter(tParameterAry[0]), cls.getNum(cparameter(tParameterAry[1])), cparameter(tParameterAry[2]));
                }
            } else if (tFunction.equals("encodeArticle")) {
                tString = encode.encodeArticle(cparameter(tParameter));
            } else if (tFunction.equals("formatByte")) {
                tString = cls.formatByte(cparameter(tParameter));
            } else if (tFunction.equals("formatDate")) {
                if (tParameterAryLength == 1) {
                    tString = cls.formatDate(cparameter(tParameter));
                }
                if (tParameterAryLength == 2) {
                    tString = cls.formatDate(cparameter(tParameterAry[0]), cls.getNum(cparameter(tParameterAry[1])));
                }
            } else if (tFunction.equals("formatText")) {
                if (tParameterAryLength == 3) {
                    tString = cls.formatText(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]), cparameter(tParameterAry[2]));
                }
            } else if (tFunction.equals("formatTextLine")) {
                if (tParameterAryLength == 2) {
                    tString = cls.formatTextLine(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]));
                }
            } else if (tFunction.equals("formatUnixStampDate")) {
                tString = cls.formatUnixStampDate(cls.getNum64(cparameter(tParameter), 0L));
            } else if (tFunction.equals("getActualRoute")) {
                tString = conf.getActualRoute(cparameter(tParameter));
            } else if (tFunction.equals("getActualRouteB")) {
                tString = conf.getActualRouteB(cparameter(tParameter));
            } else if (tFunction.equals("getActiveThings")) {
                tString = conf.getActiveThings(cparameter(tParameter));
            } else if (tFunction.equals("getLeft")) {
                if (tParameterAryLength == 2) {
                    tString = cls.getLeft(cparameter(tParameterAry[0]), cls.getNum(cparameter(tParameterAry[1]), 0));
                }
                if (tParameterAryLength == 3) {
                    tString = cls.getLeft(cparameter(tParameterAry[0]), cls.getNum(cparameter(tParameterAry[1]), 0), cparameter(tParameterAry[2]));
                }
            } else if (tFunction.equals("getLeftB")) {
                if (tParameterAryLength == 2) {
                    tString = cls.getLeftB(cparameter(tParameterAry[0]), cls.getNum(cparameter(tParameterAry[1]), 0));
                }
                if (tParameterAryLength == 3) {
                    tString = cls.getLeftB(cparameter(tParameterAry[0]), cls.getNum(cparameter(tParameterAry[1]), 0), cparameter(tParameterAry[2]));
                }
            } else if (tFunction.equals("getNum")) {
                if (tParameterAryLength == 2) {
                    tString = cls.toString(cls.getNum(cparameter(tParameterAry[0]), cls.getNum(cparameter(tParameterAry[1]), 0)));
                }
            } else if (tFunction.equals("getLRStr")) {
                if (tParameterAryLength == 3) {
                    tString = cls.getLRStr(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]), cparameter(tParameterAry[2]));
                }
            } else if (tFunction.equals("getRsValue")) {
                if (tParameterAryLength == 2) {
                    tString = conf.common.getRsValue(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]));
                }
            } else if (tFunction.equals("getString")) {
                tString = cls.getString(cparameter(tParameter));
            } else if (tFunction.equals("getSafeString")) {
                tString = cls.getSafeString(cparameter(tParameter));
            } else if (tFunction.equals("getRequestParameter")) {
                tString = conf.getRequestParameter(cparameter(tParameter));
            } else if (tFunction.equals("getRequestParameters")) {
                tString = conf.getRequestParameters(cparameter(tParameter));
            } else if (tFunction.equals("getRequestUsParameter")) {
                tString = conf.getRequestUsParameter(cparameter(tParameter));
            } else if (tFunction.equals("getRequestUsParameters")) {
                tString = conf.getRequestUsParameters(cparameter(tParameter));
            } else if (tFunction.equals("getSearchOptions")) {
                tString = conf.common.getSearchOptions(cparameter(tParameter));
            } else if (tFunction.equals("getSwitchOptions")) {
                tString = conf.common.getSwitchOptions(cparameter(tParameter));
            } else if (tFunction.equals("htmlencode")) {
                if (tParameterAryLength == 1) {
                    tString = encode.htmlencode(cparameter(tParameter));
                }
                if (tParameterAryLength == 2) {
                    tString = encode.htmlencode(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]));
                }
            } else if (tFunction.equals("htmlEncode")) {
                tString = encode.htmlencode(cparameter(tParameter));
            } else if (tFunction.equals("itake")) {
                if (tParameterAryLength == 2) {
                    tString = itake(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]));
                }
                if (tParameterAryLength == 3) {
                    tString = itake(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]), cparameter(tParameterAry[2]));
                }
                if (tParameterAryLength == 4) {
                    tString = itake(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]), cparameter(tParameterAry[2]), cparameter(tParameterAry[3]));
                }
            } else if (tFunction.equals("ireplace")) {
                if (tParameterAryLength == 2) {
                    tString = ireplace(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]));
                }
                if (tParameterAryLength == 3) {
                    tString = ireplace(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]), cparameter(tParameterAry[2]));
                }
            } else if (tFunction.equals("keywordencode")) {
                tString = encode.keywordencode(cparameter(tParameter));
            } else if (tFunction.equals("keyworddecode")) {
                tString = encode.keyworddecode(cparameter(tParameter));
            } else if (tFunction.equals("md5")) {
                tString = encode.md5(cparameter(tParameter).getBytes());
            } else if (tFunction.equals("replace")) {
                if (tParameterAryLength == 3) {
                    tString = cls.replace(cparameter(tParameterAry[0]), cparameter(tParameterAry[1]), cparameter(tParameterAry[2]));
                }
            } else if (tFunction.equals("repathdecode")) {
                tString = conf.common.repathdecode(cparameter(tParameter));
            } else if (tFunction.equals("striptags")) {
                tString = filter.striptags(cparameter(tParameter));
            } else if (tFunction.equals("urlencode")) {
                tString = conf.urlencode(cparameter(tParameter));
            } else if (tFunction.equals("ubb2html")) {
                tString = encode.ubb2html(cparameter(tParameter));
            }
        }
        return tString;
    }

    public String creplace(String argString) {
        String tString = argString;
        if (tString.indexOf("</jtbc>") >= 0) {
            String[] tJtbcAry = tString.split(Pattern.quote("</jt" + "bc>"));
            for (int ti = 0; ti < tJtbcAry.length - 1; ti++) {
                String tJtbcContent = tJtbcAry[ti];
                if (!cls.isEmpty(tJtbcContent)) {
                    if (tJtbcContent.indexOf("<jtbc") >= 0) {
                        tJtbcContent = cls.getLRStr(tJtbcContent, "<jtbc", "right");
                        String tJtbcContentParaId = "";
                        String tJtbcContentParaList = "";
                        String tJtbcContentPara = cls.getLRStr(tJtbcContent, ">", "left");
                        String tJtbcContentString = cls.getLRStr(tJtbcContent, ">", "rightr");
                        String tJtbcContentAllString = "<jtbc" + tJtbcContent + "</jtbc>";
                        if (!cls.isEmpty(tJtbcContentPara)) {
                            String[] tJtbcContentParaAry = tJtbcContentPara.split(Pattern.quote(" "));
                            for (int tk = 0; tk < tJtbcContentParaAry.length; tk++) {
                                String tJtbcContentParaK = tJtbcContentParaAry[tk].trim();
                                if (!cls.isEmpty(tJtbcContentParaK)) {
                                    tJtbcContentParaK = tJtbcContentParaK.replace("\"", "");
                                    String[] tJtbcContentParaKAry = tJtbcContentParaK.split(Pattern.quote("="));
                                    if (tJtbcContentParaKAry.length == 2) {
                                        if (tJtbcContentParaKAry[0].equals("id")) {
                                            tJtbcContentParaId = tJtbcContentParaKAry[1];
                                        }
                                        tJtbcContentParaList = tJtbcContentParaList + tJtbcContentParaK + ";";
                                    }
                                }
                            }
                        }
                        if (!cls.isEmpty(tJtbcContentParaList)) {
                            tJtbcContentParaList = cls.getLRStr(tJtbcContentParaList, ";", "leftr");
                        }
                        if (!cls.isEmpty(tJtbcContentParaId)) {
                            String[][] tJtbcContentParaItem = new String[1][2];
                            tJtbcContentParaItem[0][0] = tJtbcContentParaList;
                            tJtbcContentParaItem[0][1] = tJtbcContentString;
                            conf.njtbcelement = cls.mergeAry(conf.njtbcelement, tJtbcContentParaItem);
                        }
                        tString = tString.replace(tJtbcContentAllString, "");
                    }
                }
            }
        }
        String tvalue1, tvalue2;
        Pattern tPattern = Pattern.compile("(\\{\\$=(.[^\\}]*)\\})");
        Matcher tMatcher = tPattern.matcher(tString);
        while (tMatcher.find()) {
            tvalue1 = tMatcher.group(1);
            tvalue2 = tMatcher.group(2);
            tString = tString.replace(tvalue1, cvalue(tvalue2));
        }
        return tString;
    }

    public String[] fixParameterAry(String[] argAry) {
        String[] tAry = argAry;
        String tmpstr = "";
        String tmptstr = "";
        String tmpxstr = "";
        String tmpspstr = "{@}a{@}b{@}c{@}";
        for (int ti = 0; ti < tAry.length; ti++) {
            tmptstr = tAry[ti];
            tmptstr = tmptstr.trim();
            if (!cls.isEmpty(tmptstr)) {
                if (!tmptstr.equals("\"") && tmptstr.substring(0, 1).equals("\"") && tmptstr.substring((tmptstr.length() - 1), tmptstr.length()).equals("\"")) {
                    if (!cls.isEmpty(tmpxstr)) {
                        tmpstr += cls.getLRStr(tmpxstr, ",", "leftr") + tmpspstr;
                        tmpxstr = "";
                    }
                    tmpstr += tmptstr + tmpspstr;
                } else {
                    tmpxstr += tmptstr + ",";
                }
            } else {
                tmpxstr += ",";
            }
        }
        if (!cls.isEmpty(tmpxstr)) {
            tmpstr += cls.getLRStr(tmpxstr, ",", "leftr") + tmpspstr;
        }
        tmpstr = cls.getLRStr(tmpstr, tmpspstr, "leftr");
        String[] tmpAry = tmpstr.split(Pattern.quote(tmpspstr));
        return tmpAry;
    }

    public String getAppString(String argSourceFile, String argKeyword) {
        String tAppString = argSourceFile;
        String tKeyword = argKeyword;
        if (tAppString.indexOf("../") == -1) {
            String tNGenre = conf.getNGenre();
            if (!cls.isEmpty(tNGenre)) {
                tAppString = tNGenre + "/" + tAppString;
            }
        }
        tAppString = tAppString.replace("../", "");
        tAppString = tAppString.replace(conf.xmlsfx, "");
        tAppString = tAppString.replace("/", "_");
        tAppString = tAppString + "_" + tKeyword;
        return tAppString;
    }

    public String getReturn(String[][] argAry, String argKey) {
        String[][] tAry = argAry;
        String tKey = argKey;
        String tmpstr = "";
        if (tAry != null) {
            for (int ti = 0; ti < tAry.length; ti++) {
                if (tAry[ti][0].equals(tKey)) {
                    tmpstr = tAry[ti][1];
                    break;
                }
            }
        }
        return tmpstr;
    }

    public String[][] getXInfo(String argSourceFile, String argXField) {
        String tSourceFile = argSourceFile;
        String tXField = argXField;
        String[][] tAry = getXInfo(tSourceFile, tXField, "0");
        return tAry;
    }

    public String[][] getXInfo(String argSourceFile, String argXField, String argXSeed) {
        String tSourceFile = argSourceFile;
        String tSourceFileStr = argSourceFile;
        String tXField = argXField;
        String tXSeed = argXSeed;
        String tAppString = getAppString(tSourceFile, tXField);
        String[][] tAppAry = (String[][]) conf.application.getAttribute(conf.getAppKey(tAppString));
        String[][] tAry = tAppAry;
        if (tAry == null) {
            try {
               // File tXMLFile = new File(conf.application.getRealPath(conf.getMapPath(tSourceFileStr)).toString());
                String filepath = conf.getMapPath(tSourceFileStr);
                filepath= filepath.replace("/"+ conf.codeRoute, "");
                File tXMLFile = new File(conf.application.getRealPath(filepath).toString());
                DocumentBuilderFactory tDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder tDocumentBuilder = tDocumentBuilderFactory.newDocumentBuilder();
                Document tDocument = tDocumentBuilder.parse(tXMLFile);
                XPath tXPath = XPathFactory.newInstance().newXPath();
                Node tNode1 = (Node) tXPath.evaluate("/xml/configure/node", tDocument, XPathConstants.NODE);
                Node tNode2 = (Node) tXPath.evaluate("/xml/configure/field", tDocument, XPathConstants.NODE);
                Node tNode3 = (Node) tXPath.evaluate("/xml/configure/base", tDocument, XPathConstants.NODE);
                String tnode = tNode1.getFirstChild().getNodeValue();
                String tfield = tNode2.getFirstChild().getNodeValue();
                String tbase = tNode3.getFirstChild().getNodeValue();
                if (tfield.indexOf(",") >= 0) {
                    Integer ti = 0;
                    Integer tnodeNum = 1;
                    String[] tfieldAry = tfield.split(Pattern.quote(","));
                    for (ti = 0; ti < tfieldAry.length; ti++) {
                        if (tfieldAry[ti].equals(tXField)) {
                            tnodeNum = ti;
                        }
                    }
                    if (tnodeNum == 0) {
                        tnodeNum = 1;
                    }
                    tnodeNum = tnodeNum * 2 + 1;
                    NodeList tNodeList1 = (NodeList) tXPath.evaluate("/xml/" + tbase + "/" + tnode, tDocument, XPathConstants.NODESET);
                    Integer tNodeList1Length = tNodeList1.getLength();
                    String[][] tapAry = new String[tNodeList1Length][2];
                    for (ti = 0; ti < tNodeList1Length; ti++) {
                        NodeList tNodeList1s = tNodeList1.item(ti).getChildNodes();
                        tapAry[ti][0] = tNodeList1s.item(1).getFirstChild().getNodeValue();
                        tapAry[ti][1] = tNodeList1s.item(tnodeNum).getFirstChild().getNodeValue();
                    }
                    if (conf.isApp.equals("1")) {
                        conf.application.setAttribute(conf.getAppKey(tAppString), tapAry);
                    }
                    tAry = tapAry;
                }
            } catch (Exception e) {
                conf.application.removeAttribute(conf.getAppKey(tAppString));
                if (tXSeed.equals("0")) {
                    tAry = getXInfo(tSourceFile, tXField, "1");
                }
            }
        }
        return tAry;
    }

    public String[][] getXInfoAry(String argXInfostr, String argXInfoType, String argXField) {
        String tXInfostr = argXInfostr;
        String tXInfoType = argXInfoType;
        String tXField = argXField;
        String[] tXRouteInfo = getXRouteInfo(tXInfostr, tXInfoType);
        if (cls.isEmpty(tXField)) {
            tXField = conf.getActiveThings(tXInfoType);
        }
        return getXInfo(tXRouteInfo[0], tXField);
    }
    /*
     * 该方法返回两个值 return[0] 文件路径  return[1] 节点名称
     * ("default.channel_title", "lng") common/language/default.pro 中的 channel_title 节点的内容
     * ("global.articles:default.list", "tpl") articles/common/template/default.pro 中的 list 节点的内容
     */

    public String[] getXRouteInfo(String argXInfostr, String argXInfoType) {
        String tRoute = "";
        String tXInfostr = argXInfostr.toLowerCase();
        String tXInfoType = argXInfoType;
        if (tXInfoType.equals("cfg")) {
            tRoute = "common";
        } else if (tXInfoType.equals("lng")) {
            tRoute = "common/language";
        } else if (tXInfoType.equals("sel")) {
            tRoute = "common/language";
        } else if (tXInfoType.equals("tpl")) {
            tRoute = "common/template";
        } else {
            tRoute = "common";
        }
        if (tXInfostr.length() >= 7) {
            if (tXInfostr.substring(0, 7).equals("global.")) {
                tXInfostr = cls.getLRStr(tXInfostr, ".", "rightr");
                if (tXInfostr.indexOf(":") >= 0) {
                    tRoute = cls.getLRStr(tXInfostr, ":", "left") + "/" + tRoute;
                    tXInfostr = cls.getLRStr(tXInfostr, ":", "right");
                }
                tRoute = conf.getActualRouteB(tRoute.replace(".", "/"));
            }
        }
        String[] tAry = new String[2];
        tAry[0] = tRoute + "/" + cls.getLRStr(tXInfostr, ".", "leftr").replace(".", "/") + conf.xmlsfx;
        tAry[1] = cls.getLRStr(tXInfostr, ".", "right");
        return tAry;
    }

    public String getXRootAtt(String argSourceFile, String argName) {
        String tmpstr = "";
        String tName = argName;
        String tSourceFileStr = argSourceFile;
        try {
            File tXMLFile = new File(conf.application.getRealPath(conf.getMapPath(tSourceFileStr)).toString());
            DocumentBuilderFactory tDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder tDocumentBuilder = tDocumentBuilderFactory.newDocumentBuilder();
            Document tDocument = tDocumentBuilder.parse(tXMLFile);
            tmpstr = tDocument.getDocumentElement().getAttribute(tName);
        } catch (Exception e) {
        }
        return tmpstr;
    }

    public String itake(String argXInfostr, String argXInfoType) {
        String tmpstr = "";
        String tXInfostr = argXInfostr;
        String tXInfoType = argXInfoType;
        tmpstr = itake(tXInfostr, tXInfoType, "", "");
        return tmpstr;
    }

    public String itake(String argXInfostr, String argXInfoType, String argVars) {
        String tmpstr = "";
        String tXInfostr = argXInfostr;
        String tXInfoType = argXInfoType;
        String tVars = argVars;
        tmpstr = itake(tXInfostr, tXInfoType, tVars, "");
        return tmpstr;
    }

    public String itake(String argXInfostr, String argXInfoType, String argVars, String argXField) {
        String tXInfostr = argXInfostr;
        String tXInfoType = argXInfoType;
        String tvars = argVars;
        String tXField = argXField;
        String[] tXRouteInfo = getXRouteInfo(tXInfostr, tXInfoType);
        System.out.println(tXRouteInfo[1]);
        String[][] tDataAry = getXInfoAry(tXInfostr, tXInfoType, tXField);
        String tmpstr = getReturn(tDataAry, tXRouteInfo[1]);
        String tThis = cls.getLRStr(tXInfostr, ".", "leftr");
        String tThisGenre = cls.getLRStr(cls.getLRStr(tXInfostr, ":", "leftr"), "global.", "right");
        if (cls.isEmpty(tThisGenre) || tThisGenre.equals(tXInfostr)) {
            tThisGenre = conf.getNGenre();
        }
        tmpstr = tmpstr.replace("{$>this}", tThis);
        tmpstr = tmpstr.replace("{$>this.genre}", tThisGenre);
        //********************************************************************************
        String[] tThisGenreAry = tThisGenre.split(Pattern.quote("/"));
        int tThisGenreAryLength = tThisGenreAry.length;
        if (tThisGenreAryLength == 2) {
            tmpstr = tmpstr.replace("{$>this.genre.parents.1}", tThisGenreAry[0]);
        }
        if (tThisGenreAryLength == 3) {
            tmpstr = tmpstr.replace("{$>this.genre.parents.1}", tThisGenreAry[0] + "/" + tThisGenreAry[1]);
            tmpstr = tmpstr.replace("{$>this.genre.parents.2}", tThisGenreAry[0]);
        }
        if (tThisGenreAryLength == 4) {
            tmpstr = tmpstr.replace("{$>this.genre.parents.1}", tThisGenreAry[0] + "/" + tThisGenreAry[1] + "/" + tThisGenreAry[2]);
            tmpstr = tmpstr.replace("{$>this.genre.parents.2}", tThisGenreAry[0] + "/" + tThisGenreAry[1]);
            tmpstr = tmpstr.replace("{$>this.genre.parents.3}", tThisGenreAry[0]);
        }
        //********************************************************************************
        if (!cls.isEmpty(tvars)) {
            String[] tvarsAry = tvars.split(Pattern.quote("|"));
            for (int ti = 0; ti < tvarsAry.length; ti++) {
                String tvarsAryStr = tvarsAry[ti];
                if (!cls.isEmpty(tvarsAryStr)) {
                    String[] tvarsAryStrAry = tvarsAryStr.split(Pattern.quote("="));
                    if (tvarsAryStrAry.length == 2) {
                        tmpstr = tmpstr.replace("{$" + tvarsAryStrAry[0] + "}", tvarsAryStrAry[1]);
                    }
                }
            }
        }
        //********************************************************************************
        tmpstr = tmpstr.replace("{$>now}", cls.getDate());
        return tmpstr;
    }

    public String[][] itakes(String argXInfostr, String argXInfoType) {
        String[][] tmpAry = null;
        String tXInfostr = argXInfostr;
        String tXInfoType = argXInfoType;
        tmpAry = getXInfoAry(tXInfostr, tXInfoType, "");
        return tmpAry;
    }

    public String[][] itakes(String argXInfostr, String argXInfoType, String argXField) {
        String[][] tmpAry = null;
        String tXInfostr = argXInfostr;
        String tXInfoType = argXInfoType;
        String tXField = argXField;
        tmpAry = getXInfoAry(tXInfostr, tXInfoType, tXField);
        return tmpAry;
    }

    public String ireplace(String argXInfostr, String argXInfoType) {
        String tmpstr = "";
        String tXInfostr = argXInfostr;
        String tXInfoType = argXInfoType;
        tmpstr = ireplace(tXInfostr, tXInfoType, "");
        return tmpstr;
    }

    public String ireplace(String argXInfostr, String argXInfoType, String argVars) {
        String tmpstr = "";
        String tXInfostr = argXInfostr;
        String tXInfoType = argXInfoType;
        String tVars = argVars;
        tmpstr = itake(tXInfostr, tXInfoType, tVars);
        tmpstr = creplace(tmpstr);
        return tmpstr;
    }

    public Boolean iset(String argXInfostr, String argXInfoType, String argXField, String argXValue) {
        Boolean tbool = false;
        String tXInfostr = argXInfostr;
        String tXInfoType = argXInfoType;
        String tXField = argXField;
        String tXValue = argXValue;
        String[] tXRouteInfo = getXRouteInfo(tXInfostr, tXInfoType);
        String tSourceFileStr = tXRouteInfo[0];
        String tSourceKeyWord = tXRouteInfo[1];
        if (!cls.isEmpty(tSourceFileStr)) {
            try {
                File tXMLFile = new File(conf.application.getRealPath(conf.getMapPath(tSourceFileStr)).toString());
                DocumentBuilderFactory tDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder tDocumentBuilder = tDocumentBuilderFactory.newDocumentBuilder();
                Document tDocument = tDocumentBuilder.parse(tXMLFile);
                XPath tXPath = XPathFactory.newInstance().newXPath();
                Node tNode1 = (Node) tXPath.evaluate("/xml/configure/node", tDocument, XPathConstants.NODE);
                Node tNode2 = (Node) tXPath.evaluate("/xml/configure/field", tDocument, XPathConstants.NODE);
                Node tNode3 = (Node) tXPath.evaluate("/xml/configure/base", tDocument, XPathConstants.NODE);
                String tnode = tNode1.getFirstChild().getNodeValue();
                String tfield = tNode2.getFirstChild().getNodeValue();
                String tbase = tNode3.getFirstChild().getNodeValue();
                if (tfield.indexOf(",") >= 0) {
                    int tnodeNum = 1;
                    String[] tfieldAry = tfield.split(Pattern.quote(","));
                    for (int ti = 0; ti < tfieldAry.length; ti++) {
                        if (tfieldAry[ti].equals(tXField)) {
                            tnodeNum = ti;
                        }
                    }
                    if (tnodeNum == 0) {
                        tnodeNum = 1;
                    }
                    tnodeNum = tnodeNum * 2 + 1;
                    NodeList tNodeListEdit = (NodeList) tXPath.evaluate("/xml/" + tbase + "/" + tnode + "[" + cls.getLRStr(tfield, ",", "left") + "='" + tSourceKeyWord + "']", tDocument, XPathConstants.NODESET);
                    if (tNodeListEdit != null) {
                        NodeList tNodeListEdits = tNodeListEdit.item(0).getChildNodes();
                        tNodeListEdits.item(tnodeNum).getFirstChild().setNodeValue(tXValue);
                        TransformerFactory tTransformerFactory = TransformerFactory.newInstance();
                        Transformer tTransformer = tTransformerFactory.newTransformer();
                        DOMSource tDOMSource = new DOMSource(tDocument);
                        StreamResult tStreamResult = new StreamResult(new File(conf.application.getRealPath(conf.getMapPath(tSourceFileStr)).toString()));
                        tTransformer.transform(tDOMSource, tStreamResult);
                        tbool = true;
                    }
                }
            } catch (Exception e) {
            }
        }
        if (tbool == true) {
            String tAppString = getAppString(tSourceFileStr, tXField);
            conf.application.removeAttribute(conf.getAppKey(tAppString));
        }
        return tbool;
    }

    public sp(conf argConf) {
        conf = argConf;
    }
}